package com.zyk.filter;

import com.zyk.filter.rule.*;

import java.util.List;
import java.util.Map;

public class FilterRule {
    private final RuleType ruleType;
    private final String rule;

    public FilterRule(RuleType ruleType, String rule) {
        this.ruleType = ruleType;
        this.rule = rule;
    }

    public boolean test(String content) {
        return ruleType.getRuler().test(this.rule, content);
    }

    @Override
    public String toString() {
        return "{ruleType=" + ruleType + ", rule=" + rule + "}";
    }

    public enum RuleType {
        PREFIX(new PrefixRuler()),
        PREFIX_IC(new PrefixICRuler()),
        SUFFIX(new SuffixRuler()),
        SUFFIX_IC(new SuffixICRuler()),
        KEYWORD(new KeywordRuler()),
        KEYWORD_IC(new KeywordICRuler()),
        EQUAL(new EqualRuler()),
        EQUAL_IC(new EqualICRuler()),
        REGEXP(new RegExpRuler());

        private final Ruler ruler;

        RuleType(Ruler ruler) { // Lazy here. No lazy loading
            this.ruler = ruler;
        }

        public Ruler getRuler() {
            return ruler;
        }
    }

    public static class Properties {
        private Map<String, Data> config;


        public static class Data {
            private List<String> equal;
            private List<String> equal_ignore_case;
            private List<String> prefix;
            private List<String> prefix_ignore_case;
            private List<String> suffix;
            private List<String> suffix_ignore_case;
            private List<String> keyword;
            private List<String> keyword_ignore_case;
            private List<String> regexp;

            public List<String> getEqual() {
                return equal;
            }

            public void setEqual(List<String> equal) {
                this.equal = equal;
            }

            public List<String> getEqual_ignore_case() {
                return equal_ignore_case;
            }

            public void setEqual_ignore_case(List<String> equal_ignore_case) {
                this.equal_ignore_case = equal_ignore_case;
            }

            public List<String> getPrefix() {
                return prefix;
            }

            public void setPrefix(List<String> prefix) {
                this.prefix = prefix;
            }

            public List<String> getPrefix_ignore_case() {
                return prefix_ignore_case;
            }

            public void setPrefix_ignore_case(List<String> prefix_ignore_case) {
                this.prefix_ignore_case = prefix_ignore_case;
            }

            public List<String> getSuffix() {
                return suffix;
            }

            public void setSuffix(List<String> suffix) {
                this.suffix = suffix;
            }

            public List<String> getSuffix_ignore_case() {
                return suffix_ignore_case;
            }

            public void setSuffix_ignore_case(List<String> suffix_ignore_case) {
                this.suffix_ignore_case = suffix_ignore_case;
            }

            public List<String> getKeyword() {
                return keyword;
            }

            public void setKeyword(List<String> keyword) {
                this.keyword = keyword;
            }

            public List<String> getKeyword_ignore_case() {
                return keyword_ignore_case;
            }

            public void setKeyword_ignore_case(List<String> keyword_ignore_case) {
                this.keyword_ignore_case = keyword_ignore_case;
            }

            public List<String> getRegexp() {
                return regexp;
            }

            public void setRegexp(List<String> regexp) {
                this.regexp = regexp;
            }
        }

        public Map<String, Data> getConfig() {
            return config;
        }

        public void setConfig(Map<String, Data> config) {
            this.config = config;
        }
    }
}